package com.springboot.mybatis.service.collectiondemo;

import java.lang.reflect.Array;
import java.util.*;

public class ListTest {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        ArrayList<String> a1 = new ArrayList<>();
        a1.add(null);
        a1.add("111");
        System.out.println("a1::::"+a1);
        arrayList.add("11");
        arrayList.add("22");
        arrayList.add("33");
        arrayList.add("44");
        arrayList.add("55");
        arrayList.add(3,"00");
        Boolean isCont = arrayList.contains("00");
        String idx4 = arrayList.get(4);
        int pos00 = arrayList.indexOf("00");
        int len = arrayList.size();
        arrayList.sort(new Comparator<String>(){
            public int compare(String o1,String o2){
                return o1.compareTo(o2);
            }
        });
        System.out.println("排序后的数组队列："+arrayList);
        arrayList.set(5,"66");
        String arrStr = arrayList.toString();
        System.out.println("转成字符串格式："+arrStr);


        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("11");
        linkedList.add("22");
        linkedList.add("33");
        linkedList.add("44");
        linkedList.add("55");
        //流的使用
        linkedList.stream().filter(it -> !"33".equals(it)).forEach(System.out::println);
        //迭代器的使用
        Iterator<String> iterator = linkedList.iterator();
        while (iterator.hasNext()){
            System.out.println("输出元素：" + iterator.next());
        }
        //使用foreach迭代获取，效率更高
        for (String string:linkedList) {
            System.out.println("输出元素：" + string);
        }
        //定义可修改可查找上个元素的迭代器，可以首先设置迭代器的位置
        ListIterator<String > listIterator = linkedList.listIterator(3);
        while (listIterator.hasPrevious()){
            System.out.println("输出元素：" + listIterator.previous());
        }
    }
}
